package com.yonyou.cyxdms.basedata.service.controller.smstemplate;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.basedata.client.domains.vo.SmsTemplateVO;
import com.yonyou.cyxdms.basedata.service.dto.smstemplate.SmsTemplateDTO;
import com.yonyou.cyxdms.basedata.service.dto.smstemplate.SmsTemplatePageDTO;
import com.yonyou.cyxdms.basedata.service.service.smstemplate.SmsTemplateService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author dengqiang
 * @since 2019-09-19
 */
@RestController
@RequestMapping("/smsTemplate")
public class SmsTemplateController extends BaseController {

    @Autowired
    public SmsTemplateService smsTemplateService;

    /**
     * 短信模板分页查询
     *
     * @param current
     * @param size
     * @param vsStockAppDTO
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.yonyou.cyxdms.basedata.service.vo.smstemplate.SmsTemplateVO>
     * @author dengqiang
     * @since 2019/9/19
     */
    @ApiOperation(value="短信模板分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping(value = "/qrySmsTemplate")
    public IPage<SmsTemplateVO> qrySmsTemplatePage(@ApiParam(name = "pageNum", value = "当前页") @RequestParam("pageNum") Long current
            , @ApiParam(name = "limit", value = "分页大小") @RequestParam("limit") Long size, SmsTemplatePageDTO vsStockAppDTO) {
        Page<SmsTemplateVO> page = new Page<>(current, size);
        return smsTemplateService.qrySmsTemplatePage(page,vsStockAppDTO);
    }


    /**
     * 添加短信模板信息
     *
     * @param stDto
     * @return java.lang.Long
     * @author dengqiang
     * @since 2019/9/19
     */
    @ApiOperation(value="短信模板新增")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping(value = "/saveSmsTemplate")
    public Long addSmsTemplate(@RequestBody SmsTemplateDTO stDto) {
        return smsTemplateService.addSmsTemplate(stDto);
    }


    /**
     * 修改短信模板信息
     *
     * @param stDto
     * @return java.lang.Long
     * @author dengqiang
     * @since 2019/9/19
     */
    @ApiOperation(value="短信模板修改")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping(value = "/updateSmsTemplate")
    public Long updateSmsTemplate(@RequestBody SmsTemplateDTO stDto) {
        return smsTemplateService.updateSmsTemplate(stDto);
    }

    @ApiOperation(value="根据id查询短信模板")
    @GetMapping(value = "/getSmsTemplate")
    public SmsTemplateVO getSmsTemplateById(@RequestParam("smsTemplateId") Long smsTemplateId) {
        return smsTemplateService.getSmsTemplateById(smsTemplateId);
    }

    /**
     * 短信模板删除
     *
     * @author dengqiang
     * @since 2019/4/18
     */
    @ApiOperation(value = "短信模板删除")
    @DeleteMapping(value = "/delSmsTemplate")
    public void deleteSmsTemplate(@RequestParam(name = "smsTemplateId") Long smsTemplateId) {
        smsTemplateService.deleteSmsTemplate(smsTemplateId);
    }

    /**
     * 根据模板类型查询模板信息
     *
     * @param smsTemplateType
     * @return java.util.List<com.yonyou.cyxdms.basedata.client.domains.vo.SmsTemplateVO>
     * @author dq
     * @since 2019/12/6
     */
    @ApiOperation(value="根据模板类型查询模板信息")
    @GetMapping(value = "/getBySmsTemplateType")
    public List<SmsTemplateVO> getBySmsTemplateType(@RequestParam("smsTemplateType")String smsTemplateType) {
        return smsTemplateService.getBySmsTemplateType(smsTemplateType);
    }

}